﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Windows Forms Controls Class Library
 * Version 2.00
 * 
 * Type Toolbox Control Class
 *      Provides a UI element to act as a type-selection toobox similar to that of Visual Studio.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime;
using Adaptive.Foundation;
using Adaptive.Foundation.Reflection;
using Adaptive.Foundation.Windows.Forms;

namespace Adaptive.Foundation.CodeDom.UI
{
    /// <summary>
    /// Provides a UI element to act as a type-selection toobox similar to that of Visual Studio.
    /// </summary>
    [ToolboxItem(true),
     Description("A toolbox for selecting .NET data types"),
     Category("Code DOM")]
    public partial class TypeToolbox : ToolboxControl
    {
        /*--------------------------------------------------------------------------------
         * Public Event Definitions
         *------------------------------------------------------------------------------*/
        #region Public Event Definitions
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public TypeToolbox()
            : base()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether the object is being disposed.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                    components.Dispose();
            }
            components = null;
            base.Dispose(disposing);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Methods / Event Methods
         *------------------------------------------------------------------------------*/
        #region Protected Methods / Event Methods
        /// <summary>
        /// Creates and assigns the event handlers for the items contained within the control.
        /// </summary>
        protected override void AssignEventHandlers()
        {
            base.AssignEventHandlers();
        }
        /// <summary>
        /// Removes the event handlers for the items contained within the control.
        /// </summary>
        protected override void RemoveEventHandlers()
        {
            base.RemoveEventHandlers();
        }
        /// <summary>
        /// Raises the <see cref="E:ToolboxCloseRequest"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
        protected override void OnToolboxCloseRequest(CancelEventArgs e)
        {
            base.OnToolboxCloseRequest(e);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Public Methods / Functions
        /// <summary>
        /// 
        /// </summary>
        /// <param name="assemblyFileName"></param>
        public void AddAssembly(string assemblyFileName)
        {
            Assembly assemblyInstance = null;

            try
            {
                assemblyInstance = Assembly.LoadFile(assemblyFileName);
            }
            catch
            {
                assemblyInstance = null;
            }

            if (assemblyInstance != null)
                AddAssembly(assemblyInstance);

            assemblyInstance = null;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="assemblyFileName"></param>
        public void AddAssemblyFromGac(string assemblyFileName)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="assembly"></param>
        public void AddAssembly(Assembly assembly)
        {
            OrderedDictionary list = null;
            ToolboxCollapsiblePanel newPanel = null;
            Hashtable table = null;

            if (assembly == null)
                throw new ArgumentNullException("assembly");

            list = AssemblyTypeLoader.SortIntoNamespaces(assembly);
            foreach (DictionaryEntry entry in list)
            {
                newPanel = AddPanel((string)entry.Key, (string)entry.Key);
                table = (Hashtable)entry.Value;

                foreach (string key in table)
                {
                    List<Type> subList = (List<Type>)table[key];

                    foreach (Type listItem in subList)
                    {
                    }
                }
            }

            list.Clear();
            list = null;

        }
        /// <summary>
        /// Adds a new container panel to the toolbox.
        /// </summary>
        /// <param name="id">A name or ID to assign to the panel.</param>
        /// <param name="title">The text to display in the panel.</param>
        /// <returns>
        /// The <see cref="ToolboxCollapsiblePanel"/> instance added to the toolbox.
        /// </returns>
        public override ToolboxCollapsiblePanel AddPanel(string id, string title)
        {
            return base.AddPanel(id, title);
        }
        #endregion
    }
}
